#include<iostream>
using namespace std;
#define L 2000500
int p[L],inx[L],rank[L];
int Getfather(int x)
{
    if(x!=p[x])p[x]=Getfather(p[x]);
    return p[x];
}
void Union(int a,int b)
{
    p[b]=a;
    rank[a]+=rank[b];
    rank[b]=0;
}
int main()
{
    int n,m,i,j,a,b,s,t,k;
    char ch[3];
    t=0;
    while(cin>>n>>m)
    {
        if(n==0&&m==0)break;
        for(i=0;i<n;i++)
        {
            p[i]=i;
            inx[i]=i;
            rank[i]=1;
        }
        k=n;
        while(m--)
        {
            cin>>ch;
            if(ch[0]=='M')
            {
                cin>>a>>b;
                int ta=Getfather(inx[a]);
                int tb=Getfather(inx[b]);
                if(ta!=tb){ Union(ta,tb); }
            }
            else
            {
                cin>>s;
                int ts=Getfather(inx[s]);
                rank[ts]--;
                rank[k]=1;
                inx[s]=k;
                p[k]=k;
                k++; 
            }
        }
        int ans=0;
        for(i=0;i<k;i++)
        {
            if(rank[i]>0)ans++;
        }
        
        printf("Case #%d: %d\n",++t,ans);
    }
    return 0;
}
